var util = require('../../util.js');
var WxParse = require('../../wxParse/wxParse.js');
// pages/store/store.js
var app = getApp();
var menuType = [];
var lock = false;
Page({
  data: {
    id: 0,//好中差评
    page: 1,//页数
    total: '',//总页数
    goodsid: '',
    title: '',//标题
    image: '',//图片
    tapleft:false,

    // 产品列表
    items: [],
    count:0,
    // 加载提示
    loadTips: '',
    loading:true,
    show:true,
    scrollup:'a',
    scrolldown:'a',
    menuType: [],
    toView: '',
    act:'index',
    scrollNum: 0,
    scrollTop: 0,
    typeHeight: 36,
    goodHeight: 88,
    goodsnum:0,//购物车数量
    goodsmoney:0,//购物车价格
    tap_index:1,//当前菜单项
    show_goods:false,//商品详情的展示
  },
  onLoad: function (options) {
    var that = this;

    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight
        })
      }
    })
    that.setData({
      options: options,
      store_id: options.store_id,
    })
    // app.getLoginSession(function (session) {
    //   wx.request({
    //     url: app.api,
    //     data: {
    //       app: 'cart',
    //       act: 'drop_ajax',
    //       rec_id: 420833,
    //       t_session: session
    //     },
    //     header: {
    //       "Content-Type": "application/x-www-form-urlencoded"
    //     },
    //     method: 'POST',
    //     success: function (res) {
    //       if (!res.data.done) {
    //         that.setData({
    //           menuArr: that.data.menuArr,
    //         })
    //         wx.showToast({
    //           title: '请重试',
    //           icon: 'loading'
    //         })
    //       }
    //     },
    //     fail: function (res) {
    //       that.setData({
    //         menuArr: that.data.menuArr,
    //       })
    //       wx.showToast({
    //         title: '请重试',
    //         icon: 'loading'
    //       })

    //     }
    //   })
    // })
    that.getData();
    setTimeout(function () {
      if (that.data.statusclose != 2) {
        that.cartData(true);
      }
    }, 1000) //延迟时间 这里是1秒 
  },
  //购物车列表
  cartData:function(res){
    var that = this;
    that.setData({
      loading:res,
      first:res
    })
    console.log(res);
    app.getLoginSession(function (session) {
      wx.request({
        url: app.api,
        data: {
          app: 'cart',
          t_session:session,
          store_id: that.data.store_id
        },
        success: function (res) {
          var data = res.data;
          if(data.done&&data.retval){
            that.setData({
              loading: false
            }) 
            if(data.retval.goods!=null){
              that.setData({
                cartlist:data.retval.goods
              })
              console.log("a");
              for(var i = 0;i<that.data.cartlist.length;i++){
                console.log("bbb" + that.data.menuArr + "Sss" + that.data.first);
                if (that.data.first==true){

                  that.data.goodsnum = parseInt(that.data.cartlist[i].quantity) + parseInt(that.data.goodsnum);//设置购物车的数量
                }
                that.setData({
                  goodsnum:that.data.goodsnum,//设置购物车的数量
                  goodsmoney: data.retval.total_price//设置总价
                })
                console.log(that.data.goodsnum);
                for(var j = 0;j<that.data.menuArr.length;j++){
                  console.log(j);
                  for(var r = 0;r<that.data.menuArr[j].foods.length;r++){
                    if (that.data.cartlist[i].goods_id == that.data.menuArr[j].foods[r].goods_id){
                      that.data.menuArr[j].foods[r].goodCount = that.data.cartlist[i].quantity;//设置菜单中这个菜已经加入购物车的数量
                      that.data.menuArr[j].foods[r].goodcart = that.data.cartlist[i].rec_id;//设置菜单中这个菜已经加入购物车的购物车id
                      that.setData({
                        menuArr:that.data.menuArr
                      })
                    }
                  }
                }
              }
            }
          }else{
            that.setData({
              loading:false
            })
          }
        },
        fail:function(){
          that.setData({
            loading:false
          })
        }
      })
    })
    
  },
  //菜单切换
  tap:function(e){
    var index = e.currentTarget.dataset.index;
    var that = this;
    that.setData({
      tap_index:index
    })
    if (that.data.tap_index == 2) {
      wx.request({
        url: app.api,
        data:{
          app:'store',
          act:'get_store_comment',
          store_id:that.data.store_id
        },
        success:function(res){
          var data = res.data;
          if(data.done&&data.retval){
            if (data.retval[0].count>0){
              that.setData({
                count: data.retval[0].count,
                loading:false,
                comment: that.deallist(app.turn(data.retval[0].commentArr)).reverse()
              })
              for(var i = 0;i<that.data.comment.length;i++){
                that.data.comment[i].performance_cost = parseInt(that.data.comment[i].performance_cost);
                that.setData({
                  comment:that.data.comment
                })
              }
            }else{
              that.setData({
                loading:false,
                loadTips:'暂无评论'
              })
            }
          }else{
            that.setData({
              loading: false,
              loadTips: '暂无评论'
            })
          }
        },
        fail:function(){
          that.setData({
            loading: false,
            loadTips: '接口连接错误'
          })
        }
      })

    } else if (that.data.tap_index == 3) {
      wx.request({
        url: app.api,
        data: {
          app: 'store',
          act: 'get_detail',
          store_id: that.data.store_id
        },
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
              that.setData({
                loading: false,
                coupon:data.retval.couponList,
                sale: app.turn(data.retval.sale_promotion),
                stores:data.retval.store,
                call:data.retval.store.tel
              }) 
          } else {
            that.setData({
              loading: false,
              loadTips: '暂无相关信息'
            })
          }
        },
        fail: function () {
          that.setData({
            loading: false,
            loadTips: '接口连接错误'
          })
        }
      })
    } else {
      wx.request({

        // 请求地址
        url: app.api,

        // 请求参数
        data: {
          app: 'store',
          act: 'index',
          store_id: that.data.store_id
        },

        // 请求成功
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
            if (data.retval.status == '2') {
              that.setData({
                loading: true,
                statusclose: 2,
                errorTips: '该店铺不存在！'
              })
            } else {
              that.setData({
                loading: false,
                menuArr: that.add(app.turn(data.retval.menuArr)),
                store: data.retval.store,
                menuType: that.type(app.turn(data.retval.menuArr)),
                toView: menuType[0]
              })
            }
            console.log(that.data.toView);
          }
        },
        // 请求失败
        fail: function () {
          that.setData({
            loading: true,
            errorTips: '加载数据失败！'
          })
        },

      });
      wx.request({
        url: app.api,
        data: {
          app: 'store',
          act: 'get_store_comment',
          store_id: that.data.store_id
        },
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
            if (data.retval[0].count > 0) {
              that.setData({
                count: data.retval[0].count,
                loading: false,
                loadTips: '',
                comment: that.deallist(app.turn(data.retval[0].commentArr)).reverse()
              })
            } else {
              that.setData({
                count: data.retval[0].count,
                loading: false,
                loadTips: '暂无评论'
              })
            }
          } else {
            that.setData({
              loading: false,
              loadTips: '暂无评论'
            })
          }
        },
        fail: function () {
          that.setData({
            loading: false,
            loadTips: '接口连接错误'
          })
        }
      })
    }
  },
  goodsScrollAct: function (e) {
    console.log(e);
    var typeCount = this.data.menuType.length;
    var goodsCount = 0
    this.data.menuArr.forEach((item) => {
      goodsCount += item.foods.length;
    });

    var heightList = [0];
    var curHeight = 0;
    this.data.menuArr.forEach((item) => {
      curHeight += (this.data.typeHeight + item.foods.length * this.data.goodHeight);
      heightList.push(curHeight);
      console.log(item.foods.length)
    });
    if (this.data.tapleft!=true){
      for (var i = 0; i < heightList.length; i++) {
        console.log(heightList[i]);
        if (e.detail.scrollTop >= heightList[i] && e.detail.scrollTop < heightList[i + 1]) {
          this.setData({
            scrollNum: i
          });

          console.log(this.data.scrollNum);
        }
      }
    }else{
      this.setData({
        tapleft:false
      })
    }
    
  },
  selectMenuAct: function (e) {
    var id = e.target.dataset.id;
    var tType = this.data.menuType[id];
    this.setData({
      scrollNum: id,
      toView: tType,
      tapleft:true,
    });
    console.log(this.data.scrollNum+"aaa"+tType);
  },
  increaseAct: function (e) {
    if(lock==true) return false;
    lock=true;
    var that = this;
    var goodid = e.currentTarget.dataset.goodid;
    var typeid = e.currentTarget.dataset.typeid;
    var id = e.currentTarget.dataset.id;
    that.data.menuArr[typeid].foods[goodid].goodCount++;
    that.setData({
      menuArr: that.data.menuArr,
      goodsnum:that.data.goodsnum+1,
      goodsmoney: parseInt(that.data.goodsmoney) +parseInt(e.currentTarget.dataset.money)
    });

      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'cart',
            act: 'add',
            id: id,
            spec_id: 0,
            quantity: 1,
            t_session:session
          },
          success:function(res){
            var data = res.data;
            if(data.done==false){
              wx.showToast({
                title: '加入购物车失败',
                icon:'loading'
              })
              that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount - 1;
              that.setData({
                menuArr: that.data.menuArr,
                goodsnum: that.data.goodsnum - 1,
              })
            }else{
              that.setData({
                addgoodlist: app.turn(data.retval.carts.goods)
              })
              for (var i = 0; i < that.data.addgoodlist.length;i++){
                if (that.data.addgoodlist[i].goods_id==id){
                  that.data.menuArr[typeid].foods[goodid].goodcart = that.data.addgoodlist[i].rec_id;
                  that.setData({
                    menuArr: that.data.menuArr,
                  })
                  console.log(that.data.menuArr);
                }
              }
              that.cartData();
            }
          },
          fail:function(){
            that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount - 1;
            that.setData({
              menuArr: that.data.menuArr,
              goodsnum: that.data.goodsnum - 1,
            })
            wx.showToast({
              title: '加入购物车失败',
              icon: 'loading'
            })
          },
          complete:function(){
            lock=false;
          }
        })
      })
   
  },
  decreaseAct: function (e) {
    if(lock==true) return false;
    lock=true;
    var that = this;
    var goodid = e.currentTarget.dataset.goodid;
    var typeid = e.currentTarget.dataset.typeid;
    var id = e.currentTarget.dataset.id;
    var rec_id = e.currentTarget.dataset.recid;
    that.data.menuArr[typeid].foods[goodid].goodCount--;
    that.setData({
      menuArr: that.data.menuArr,
      goodsnum: that.data.goodsnum -1,
      goodsmoney: parseInt(that.data.goodsmoney) - parseInt(e.currentTarget.dataset.money)
    });
    if (that.data.menuArr[typeid].foods[goodid].goodCount==0){
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'cart',
            act: 'drop_ajax',
            rec_id: rec_id,
            t_session: session
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            var data = res.data;
            if(data.done==false){
              that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount + 1;
              that.setData({
                menuArr: that.data.menuArr,
                goodsnum: that.data.goodsnum - 1,
              })
              wx.showToast({
                title: '请重试',
                icon: 'loading'
              })
            }else{
              that.cartData();
            }
          },
          fail: function (res) {
            that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount + 1;
            that.setData({
              menuArr: that.data.menuArr,
            })
            wx.showToast({
              title: '请重试',
              icon: 'loading'
            })

          },
          complete:function(){
            lock=false;
          }
        })
      })
    }else{
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'cart',
            act: 'update',
            rec_id: rec_id,
            goods_id: id,
            spec_id: 0,
            quantity: that.data.menuArr[typeid].foods[goodid].goodCount,
            t_session: session
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            var data = res.data;
            if (data.done == false) {
              that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount + 1;
              that.setData({
                menuArr: that.data.menuArr,
                goodsnum: that.data.goodsnum - 1,
              })
              wx.showToast({
                title: '请重试',
                icon: 'loading'
              })
            }else{
              that.cartData();
            }
          },
          fail: function (res) {
            that.data.menuArr[typeid].foods[goodid].goodCount = that.data.menuArr[typeid].foods[goodid].goodCount + 1;
            that.setData({
              menuArr: that.data.menuArr,
              goodsnum: that.data.goodsnum - 1,
            })
            wx.showToast({
              title: '请重试',
              icon: 'loading'
            })
          },
          complete:function(){
            lock=false;
          }
        })
      })
    }
      
    
       
  },
  //购物车列表的编辑，整加或减少
  increaseactList: function (e) {
    if (lock==true) return false;
    lock=true;
    var that = this;
    var id = e.currentTarget.dataset.id;
    var number = e.currentTarget.dataset.number;
    var money = e.currentTarget.dataset.money;
    var index = e.currentTarget.dataset.index;
    app.getLoginSession(function (session) {
      wx.request({
        url: app.api,
        data: {
          app: 'cart',
          act: 'add',
          id: id,
          spec_id: 0,
          quantity: 1,
          t_session: session
        },
        success: function (res) {
          var data = res.data;
          if (data.done == true) {
            for (var i = 0; i < that.data.menuArr.length; i++) {
              for (var j = 0; j < that.data.menuArr[i].foods.length; j++) {
                if (that.data.menuArr[i].foods[j].goods_id == id) {
                  that.data.menuArr[i].foods[j].goodCount = number;
                  that.setData({
                    menuArr: that.data.menuArr
                  })
                }
              }
            }
            that.data.cartlist[index].quantity = number;
            that.setData({
              goodsnum: parseInt(that.data.goodsnum) + parseInt(1),//购物车数量
              goodsmoney: parseInt(that.data.goodsmoney) + parseInt(money),//购物车价格
              cartlist:that.data.cartlist
            })
            that.cartData();
          } else {
            wx.showToast({
              title: '添加失败！',
              icon: 'loading'
            })
          }
        },
        fail: function () {
          wx.showToast({
            title: '添加失败',
            icon: 'loading'
          })
        },
        complete:function(){
          lock=false;
        }
      })
    })

  },
  decreaseactList: function (e) {
    if (lock==true) return false;
    lock=true;
    var that = this;
    var id = e.currentTarget.dataset.id;
    var number = e.currentTarget.dataset.number;
    var money = e.currentTarget.dataset.money;
    var rec_id = e.currentTarget.dataset.recid;
    var index = e.currentTarget.dataset.index;
    if(number<0) return false;
    if (number == 0) {
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'cart',
            act: 'drop_ajax',
            rec_id: rec_id,
            t_session: session
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            var data = res.data;
            if (data.done == true) {
              for (var i = 0; i < that.data.menuArr.length; i++) {
                for (var j = 0; j < that.data.menuArr[i].foods.length; j++) {
                  if (that.data.menuArr[i].foods[j].goods_id == id) {
                    that.data.menuArr[i].foods[j].goodCount = number;
                    that.setData({
                      menuArr: that.data.menuArr
                    })
                  }
                }
              }
              that.data.cartlist[index].quantity = number;
              that.setData({
                cartlist:that.data.cartlist,
                goodsnum: parseInt(that.data.goodsnum) - parseInt(1),//购物车数量
                goodsmoney: parseInt(that.data.goodsmoney) - parseInt(money),//购物车价格
              })
              that.cartData();
              if(that.data.goodsnum==0){
                that.setData({
                  showModalStatus:false
                })
              }
            }else{
              wx.showToast({
                title: '请重试',
                icon: 'loading'
              })
            }
          },
          fail: function (res) {
            wx.showToast({
              title: '请重试',
              icon: 'loading'
            })

          },
          complete:function(){
            lock=false;
          }
        })
      })
    } else {
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'cart',
            act: 'update',
            rec_id: rec_id,
            goods_id: id,
            spec_id: 0,
            quantity: number,
            t_session: session
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          success: function (res) {
            var data = res.data;
            if (data.done == true) {
              for (var i = 0; i < that.data.menuArr.length; i++) {
                for (var j = 0; j < that.data.menuArr[i].foods.length; j++) {
                  if (that.data.menuArr[i].foods[j].goods_id == id) {
                    that.data.menuArr[i].foods[j].goodCount = number;
                    that.setData({
                      menuArr: that.data.menuArr
                    })
                  }
                }
              }
              that.data.cartlist[index].quantity = number;
              that.setData({
                cartlist: that.data.cartlist,
                goodsnum: parseInt(that.data.goodsnum) - parseInt(1),//购物车数量
                goodsmoney: parseInt(that.data.goodsmoney) - parseInt(money),//购物车价格
              })
              that.cartData();
            }else{
              wx.showToast({
                title: '请重试',
                icon: 'loading'
              }) 
            }
          },
          fail: function (res) {
            wx.showToast({
              title: '请重试',
              icon: 'loading'
            })
          },
          complete:function(){
            lock=false;
          }
        })
      })
    }
  },
  // 评论
  // 获取数据
  getData: function(index) {

    var that = this;
    // 加载前
    that.setData({
      loadTips: that.data.errorTips ? '加载中...' : ''
    })
    wx.request({

      // 请求地址
      url: app.api,

      // 请求参数
      data: {
        app: 'store',
        act: 'index',
        store_id: that.data.store_id
      },

      // 请求成功
      success: function (res) {
        var data = res.data;
        if(data.done&&data.retval){
          if (data.retval.store.state == '2'){
            that.setData({
              loading:true,
              statusclose:2,
              errorTips:'该店铺不存在！'
            })
          }else{
            that.setData({
              menuArr: that.add(app.turn(data.retval.menuArr)),
              store: data.retval.store,
              menuType: that.type(app.turn(data.retval.menuArr)),
              toView: menuType[0]
            })
          }
          console.log(that.data.toView);
        }
      },
      // 请求失败
      fail: function () {
        that.setData({
          loading:true,
          errorTips: '加载数据失败！'
        })
      },

    });
    if (that.data.statusclose != 2) {
      wx.request({
        url: app.api,
        data: {
          app: 'store',
          act: 'get_store_comment',
          store_id: that.data.store_id
        },
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
            if (data.retval[0].count > 0) {
              that.setData({
                count: data.retval[0].count,
                loadTips: '',
                comment: that.deallist(app.turn(data.retval[0].commentArr)).reverse()
              })
            } else {
              that.setData({
                count: data.retval[0].count
              })
            }
          } else {
            that.setData({
              loading: false
            })
          }
        },
        fail: function () {
          that.setData({
            loading: false
          })
        }
      })
    }
  },
  //上拉刷新
  onReachBottom: function () {
    var that = this;
    that.setData({
      page: parseInt(that.data.page) + 1
    })
    wx.request({

      // 请求地址
      url: app.api,

      // 请求参数
      data: {
        app: 'goods',
        act: 'get_goods_comments',
        goods_id: that.data.options.goods_id,
        page: that.data.page,
        buyer_attitude: that.data.id,
        size: 10
      },

      // 请求成功
      success: function (res) {
        var data = res.data;
        var item = data.retval.goods_comments;
        if (data.retval.goods_comments.length != 0) {
          that.setData({
            items: that.data.items.concat(item),
            loading: false,
          });
        } else {
          wx.stopPullDownRefresh()
          that.setData({
            loading: false,
            loadTips: '加载完毕'
          })
        }

      },

      // 请求失败
      fail: function () {
        console.log('aa');
        that.setData({
          loading: false,
          loadTips: '加载数据失败！'
        })
      },
    });
  },
  //查看图片
  showimage: function (e) {
    wx.previewImage({
      current: e.currentTarget.dataset.imgs[e.currentTarget.dataset.index], // 当前显示图片的http链接
      urls: e.currentTarget.dataset.imgs // 需要预览的图片http链接列表
    })
  },
  //抽屉层
  setModalStatus: function (e) {
    console.log("设置显示状态，1显示0不显示", e.currentTarget.dataset.status);
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export()
    })
    if (e.currentTarget.dataset.status == 1) {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation
      })
      if (e.currentTarget.dataset.status == 0) {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)
    this.cartData();
  },
  // 查看二维码
  showcode:function(){
    var that = this;
    var arr = [that.data.store.store_qrcode];
    wx.previewImage({
      current: that.data.store.store_qrcode,
      urls:arr
    })
  },
  //商品详情弹出层
  show_goods:function(res){
    var that = this;
    console.log("弹出层");
    that.setData({
      show_goods: that.data.show_goods==true?false:true,
    })
    if(that.data.show_goods==true){
      that.setData({
        price: res.currentTarget.dataset.price || '',
        sale: res.currentTarget.dataset.sale || '',
        image: res.currentTarget.dataset.image || '',
        name: res.currentTarget.dataset.name || '',
        description:res.currentTarget.dataset.description||''
      })
    }
  },
  call:function(){
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.call //仅为示例，并非真实的电话号码
    })
  },
  deallist(list) {
    if (list && Array.isArray(list)) {
      list.forEach((item) => {
        console.log(item);
        item.buyer_evaluation_time = util.formatDate(new Date(item.buyer_evaluation_time * 1000), 'YY-MM-dd');
      })
      return list
    }
  },
  getcoupon:function(res){
    var that = this;
    console.log(res);
    var coupon = res.currentTarget.dataset.coupon;
    var store = res.currentTarget.dataset.store;
    app.getLoginSession(function (session) {
      wx.request({
        url: app.api,
        data: {
          app:'my_coupon',
          act:'receiveCoupon',
          couponId:coupon,
          store_id:store,
          t_session:session
        },
        success:function(res){
          console.log(res)
          var data = res.data;
          if(data.done&&data.retval){
            if(data.retval=="0"){
              wx.showToast({
                title: data.msg,
                icon: 'loading',
              })
            }else{
              wx.showToast({
                title: '领取成功！',
              })
              that.setData({
                loading:true
              })
              wx.request({
                url: app.api,
                data: {
                  app: 'store',
                  act: 'get_detail',
                  store_id: that.data.store_id
                },
                success: function (res) {
                  var data = res.data;
                  if (data.done && data.retval) {
                    that.setData({
                      loading: false,
                      coupon: data.retval.couponList,
                      sale: app.turn(data.retval.sale_promotion),
                      stores: data.retval.store
                    })
                  } else {
                    that.setData({
                      loading: false,
                      loadTips: '暂无相关信息'
                    })
                  }
                },
                fail: function () {
                  that.setData({
                    loading: false,
                    loadTips: '接口连接错误'
                  })
                }
              })
            }
          }
        },
        fail:function(res){
          wx.showToast({
            title: '接口连接失败，请重试',
          })
        }
      })
    })
    
  },
  turn: function (list) {//对下标重新赋值下标从0开始
    var arr = [];
    for (var i in list) {
      var str = list[i]
      arr.push(str);
    }
    arr.forEach((item) => {
      item.goodCount = 0;
      item.goodcart=''
    })
    list = arr;
    return list
  },
  type:function(list){
    if (list && Array.isArray(list)) {
      list.forEach((item) => {
        var i = "a"+menuType.length;
        console.log(i);
        menuType.push(i)
      })
      return menuType
    }
  },
  add:function(list){
    var that = this;
    var arr = [];
    var a = 0;
    if (list && Array.isArray(list)) {
      list.forEach((item) => {
        item.id="a"+a++;
        item.foods=that.turn(item.foods);
      })
      console.log(list)
      return list
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})